package com.hinotoyk.testsystem.service;

import com.hinotoyk.testsystem.entity.*;
import com.hinotoyk.testsystem.mappers.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class QuestionService {
    @Resource
    private SGQuestionMapper sgMapper;

    @Resource
    private PLQuestionMapper plMapper;

    @Resource
    private TOFQuestionMapper tofMapper;

    @Resource
    private FillingQuestionMapper fillMapper;

    @Resource
    private EssayQuestionMapper essayMapper;

    // SGQuestion start
    public List<SGQuestion> FindSGQuestionByDifficult(int difficult){
        SGQuestionExample e = new SGQuestionExample();
        e.createCriteria().andDifficultEqualTo(difficult);
        List<SGQuestion> list = sgMapper.selectByExample(e);
        System.out.println(list);
        return list;
    }
    
    public List<SGQuestion> FindSGQuestionByTeacherId(int tid){
        SGQuestionExample e = new SGQuestionExample();
        e.createCriteria().andTeacherIdEqualTo(tid);
        return sgMapper.selectByExample(e);
    }

    public SGQuestion FindSGQuestion(int id){
        return sgMapper.selectByPrimaryKey(id);
    }

    public boolean AddSGQuestion(SGQuestion question){
        return sgMapper.insert(question) != 0;
    }

    public boolean DeleteSGQuestion(int id){
        return sgMapper.deleteByPrimaryKey(id) != 0;
    }

    public boolean UpdateSGQuestion(SGQuestion question){
        return sgMapper.updateByPrimaryKey(question) != 0;
    }
    // SGQuestion end

    // PLQuestion start
    public List<PLQuestion> FindPLQuestionByDifficult(int difficult){
        PLQuestionExample e = new PLQuestionExample();
        e.createCriteria().andDifficultEqualTo(difficult);
        return plMapper.selectByExample(e);
    }
    
    public List<PLQuestion> FindPLQuestionByTeacherId(int tid){
        PLQuestionExample e = new PLQuestionExample();
        e.createCriteria().andTeacherIdEqualTo(tid);
        return plMapper.selectByExample(e);
    }

    public PLQuestion FindPLQuestion(int id){
        return plMapper.selectByPrimaryKey(id);
    }

    public boolean AddPLQuestion(PLQuestion question){
        return plMapper.insert(question) != 0;
    }

    public boolean DeletePLQuestion(int id){
        return plMapper.deleteByPrimaryKey(id) != 0;
    }

    public boolean UpdatePLQuestion(PLQuestion question){
        return plMapper.updateByPrimaryKey(question) != 0;
    }
    // PLQuestion end

    // TOFQuestion start
    public List<TOFQuestion> FindTOFQuestionByDifficult(int difficult){
        TOFQuestionExample e = new TOFQuestionExample();
        e.createCriteria().andDifficultEqualTo(difficult);
        return tofMapper.selectByExample(e);
    }
    
    public List<TOFQuestion> FindTOFQuestionByTeacherId(int tid){
        TOFQuestionExample e = new TOFQuestionExample();
        e.createCriteria().andTeacherIdEqualTo(tid);
        return tofMapper.selectByExample(e);
    }
    public TOFQuestion FindTOFQuestion(int id){
        return tofMapper.selectByPrimaryKey(id);
    }

    public boolean AddTOFQuestion(TOFQuestion question){
        return tofMapper.insert(question) != 0;
    }

    public boolean DeleteTOFQuestion(int id){
        return tofMapper.deleteByPrimaryKey(id) != 0;
    }

    public boolean UpdateTOFQuestion(TOFQuestion question){
        return tofMapper.updateByPrimaryKey(question) != 0;
    }

    // TOFQuestion end

    // FillingQuestion start
    public List<FillingQuestion> FindFillQuestionByDifficult(int difficult){
        FillingQuestionExample e = new FillingQuestionExample();
        e.createCriteria().andDifficultEqualTo(difficult);
        return fillMapper.selectByExample(e);
    }

    public List<FillingQuestion> FindFillingQuestionByTeacherId(int tid){
        FillingQuestionExample e = new FillingQuestionExample();
        e.createCriteria().andTeacherIdEqualTo(tid);
        return fillMapper.selectByExample(e);
    }

    public FillingQuestion FindFillingQuestion(int id){
        return fillMapper.selectByPrimaryKey(id);
    }

    public boolean AddFillingQuestion(FillingQuestion question){
        return fillMapper.insert(question) != 0;
    }

    public boolean DeleteFillingQuestion(int id){
        return fillMapper.deleteByPrimaryKey(id) != 0;
    }

    public boolean UpdateFillingQuestion(FillingQuestion question){
        return fillMapper.updateByPrimaryKey(question) != 0;
    }
    // FillingQuestion end

    // EssayQuestion start
    public List<EssayQuestion> FindEssayQuestionByDifficult(int difficult){
        EssayQuestionExample e = new EssayQuestionExample();
        e.createCriteria().andDifficultEqualTo(difficult);
        return essayMapper.selectByExample(e);
    }

    public List<EssayQuestion> FindEssayQuestionByTeacherId(int tid){
        EssayQuestionExample e = new EssayQuestionExample();
        e.createCriteria().andTeacherIdEqualTo(tid);
        return essayMapper.selectByExample(e);
    }
    public EssayQuestion FindEssayQuestion(int id){
        return essayMapper.selectByPrimaryKey(id);
    }

    public boolean AddEssayQuestion(EssayQuestion question){
        return essayMapper.insert(question) != 0;
    }

    public boolean DeleteEssayQuestion(int id){
        return essayMapper.deleteByPrimaryKey(id) != 0;
    }

    public boolean UpdateEssayQuestion(EssayQuestion question){
        return essayMapper.updateByPrimaryKey(question) != 0;
    }
    // EssayQuestion end
}
